//----------------------------------Include-------------------------------------
#include <stdio.h>
#include <string.h>
#include <stdint.h>

#include "mcu.h"
#include "board.h"
#include "glbvar.h"
//#include "fonts.h"
//------------------------------------------------------------------------------

//-----------------------------------Macro--------------------------------------
#define  BG_COLOR     BLACK
#define  FR_COLOR     WHITE
//------------------------------------------------------------------------------

//------------------------------------Type--------------------------------------
typedef struct{
  uint32_t   x;
  uint32_t   y;
  uint32_t   w;
  uint32_t   h;
}t_win;
//------------------------------------------------------------------------------

//---------------------------------Static Var-----------------------------------
static  t_win     nt_wavewin;
static  uint32_t  draw_pt;
//------------------------------------------------------------------------------

//--------------------------------Static Func-----------------------------------
static void _show_point(float v)
{
  uint32_t   x,y;
  x = nt_wavewin.x + draw_pt +2;
  if(x>= nt_wavewin.w) return;
  y = nt_wavewin.y + nt_wavewin.h/2 - v*40;
  
  brd_lcd_draw_vline(x, nt_wavewin.y + nt_wavewin.h/2 -100, 100*2, BG_COLOR);    //erase
  brd_lcd_draw_point(x, y, FR_COLOR);
  
  draw_pt++;
}
//------------------------------------------------------------------------------

//---------------------------------Public Func----------------------------------
void disp_show_wave(void)
{
  draw_pt = 0;
  for(uint32_t i=0; i<GM_SAMP_LEN; i++){
    _show_point(igaf_adc_u[i]);
  }
}
//------------------------------------------------------------------------------
void disp_init(void)
{
  nt_wavewin.x = 0;
  nt_wavewin.y = 0;
  nt_wavewin.w = 700;
  nt_wavewin.h = 400;
  
  brd_lcd_draw_hline(nt_wavewin.x, nt_wavewin.y+nt_wavewin.h,   nt_wavewin.w, FR_COLOR);
  brd_lcd_draw_hline(nt_wavewin.x, nt_wavewin.y+nt_wavewin.h+1, nt_wavewin.w, FR_COLOR);
  
  brd_lcd_draw_vline(nt_wavewin.x,   nt_wavewin.y, nt_wavewin.h, FR_COLOR);
  brd_lcd_draw_vline(nt_wavewin.x+1, nt_wavewin.y, nt_wavewin.h, FR_COLOR);
}
//-----------------------------------EOF----------------------------------------






